package com.ruoyi.web.controller.fund;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.cost.domain.HouseBatchDetailT;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.costBatch.domain.HouseBatchT;
import com.ruoyi.costBatch.service.IHouseBatchTService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 批量缴费Controller
 * 
 * @author lijie
 * @date 2023-04-24
 */
@RestController
@RequestMapping("/fund/costBatch")
public class HouseBatchTController extends BaseController
{
    @Autowired
    private IHouseBatchTService houseBatchTService;

    /**
     * 查询批量缴费列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HouseBatchT houseBatchT)
    {
        startPage();
        List<HouseBatchT> list = houseBatchTService.selectHouseBatchTList(houseBatchT);
        return getDataTable(list);
    }

    /**
     * 导出批量缴费列表
     */
    @Log(title = "批量缴费", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HouseBatchT houseBatchT)
    {
        List<HouseBatchT> list = houseBatchTService.selectHouseBatchTList(houseBatchT);
        ExcelUtil<HouseBatchT> util = new ExcelUtil<HouseBatchT>(HouseBatchT.class);
        util.exportExcel(response, list, "批量缴费数据");
    }

    /**
     * 获取批量缴费详细信息
     */
    @GetMapping(value = "/{batchId}")
    public AjaxResult getInfo(@PathVariable("batchId") Long batchId)
    {
        return AjaxResult.success(houseBatchTService.selectHouseBatchTByBatchId(batchId));
    }

    /**
     * 新增批量缴费
     */
    @Log(title = "批量缴费", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HouseBatchT houseBatchT)
    {
        houseBatchT.setCreater(getUsername());
        return toAjax(houseBatchTService.insertHouseBatchT(houseBatchT));
    }

    /**
     * 修改批量缴费
     */
    @Log(title = "批量缴费", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HouseBatchT houseBatchT)
    {
        return toAjax(houseBatchTService.updateHouseBatchT(houseBatchT));
    }

    /**
     * 删除批量缴费
     */
    @Log(title = "批量缴费", businessType = BusinessType.DELETE)
	@DeleteMapping("/{batchIds}")
    public AjaxResult remove(@PathVariable Long[] batchIds)
    {
        return toAjax(houseBatchTService.deleteHouseBatchTByBatchIds(batchIds));
    }

    /**
     * 执行批量缴费
     */
    @Log(title = "批量缴费", businessType = BusinessType.UPDATE)
    @GetMapping(value = "/executeCostBatch/{batchIds}/{costDate}")
    public AjaxResult executeCostBatch(@PathVariable("batchIds") Long[] batchIds,@PathVariable("costDate") String costDate)
    {
        HouseBatchDetailT houseBatchDetailT = new HouseBatchDetailT();
        houseBatchDetailT.setCreater(getUsername());
        return toAjax(houseBatchTService.updateExecuteCostBatch(houseBatchDetailT,batchIds,DateUtils.dateTime("yyyy-MM-dd",costDate)));
    }
}
